package com.kayt.cyberBar.cuser.business.dao.impl;

import java.sql.SQLException;
import java.util.LinkedHashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.kayt.cyberBar.common.PageData;
import com.kayt.cyberBar.common.dao.EntityDao;
import com.kayt.cyberBar.cuser.business.dao.ICyberBaseTaskReplyDao;
import com.kayt.cyberBar.cuser.business.entity.po.BCyberBaseTaskReply;

@Repository("iCyberBaseTaskReplyDao")
public class CyberBaseTaskReplyDaoImpl implements ICyberBaseTaskReplyDao {
	
	@Autowired
	private EntityDao entityDao;

	@Override
	public Long addReply(BCyberBaseTaskReply reply) throws SQLException {
		if (reply != null) {
			return this.entityDao.save(reply);
		}
		return 0L;
	}
	
	@Override
	public void updateReply (BCyberBaseTaskReply reply) throws SQLException {
		if (reply != null) {
			this.entityDao.update(reply);
		}
	}
	
	@Override
	public int deleteReply (String reply) {
		if (reply != null) {
			this.entityDao.deleteDetached(reply);
			return 0;
		}
		return -1;
	}
	
	@Override
	public BCyberBaseTaskReply getReply (String replyId) {
		BCyberBaseTaskReply bReplySent = null;
		if (replyId != null) {
			Long id;
			try {
				id = Long.parseLong(replyId);
			} catch (Exception e) {
				return null;
			}
			bReplySent = this.entityDao.findById(id, BCyberBaseTaskReply.class);
		}
		return bReplySent;
	}
	
	@Override
	public BCyberBaseTaskReply getReplyByCode (String code) throws SQLException {
		BCyberBaseTaskReply bReplySent = null;
		if (code != null) {
			bReplySent = this.entityDao.getObj(BCyberBaseTaskReply.class, " o.code=? ", new Object[]{code});
		}
		return bReplySent;
	}
	
	@Override
	public void batchInsert(List<BCyberBaseTaskReply> sentList) {
		this.entityDao.batchInsert(sentList);
	}
	
	@Override
	public PageData<BCyberBaseTaskReply> getReplyList (int pageNum, int pageSize, String hql, Object[] params, LinkedHashMap<String, String> replyMap) throws SQLException {
		return this.entityDao.getPagingData(BCyberBaseTaskReply.class, pageNum, pageSize, hql, params, replyMap);
	}
	
	@Override
	public List getReplyListByHql(int pageNum, int pageSize, String hql, Object[] params) throws SQLException {
		return this.entityDao.getPagingDataByHql(pageNum, pageSize, hql, params);
	}
}
